package com.qiguliuxing.dts.core.system;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import com.qiguliuxing.dts.core.util.SystemInfoPrinter;

/**
 * 系统启动服务，用于检查系统状态及打印系统信息
 */

@SuppressWarnings("unused")
@Component
class SystemInistService {
	private SystemInistService systemInistService;

	@Autowired
	private ConfigService configService;

	@Autowired
	private Environment environment;

	@PostConstruct
	private void inist() {
		systemInistService = this;

		try {
			SystemInfoPrinter.printInfo("dts 初始化信息", getSystemInfo());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private Map<String, String> getSystemInfo() {

		Map<String, String> systemMap = new LinkedHashMap<>();

		systemMap.put(SystemInfoPrinter.CREATE_PART_COPPER + 0, "系统信息");
		// 测试获取application-db.yml配置信息
		systemMap.put("服务器端口", environment.getProperty("server.port"));
		systemMap.put("数据库USER", environment.getProperty("spring.datasource.druid.username"));
		systemMap.put("数据库地址", environment.getProperty("spring.datasource.druid.url"));
		systemMap.put("调试级别", environment.getProperty("logging.level.com.qiguliuxing.dts.wx"));
		systemMap.put("本地启动访问目录前缀",environment.getProperty("server.servlet.context-path"));

		systemMap.put("laocl 访问地址：", "http://localhost:" + environment.getProperty("server.port")  + environment.getProperty("server.servlet.context-path") + "/swagger-ui.html#/");

		// 测试获取application-core.yml配置信息
		systemMap.put(SystemInfoPrinter.CREATE_PART_COPPER + 1, "模块状态");
		systemMap.put("邮件", environment.getProperty("dts.notify.mail.enable"));
		systemMap.put("短信", environment.getProperty("dts.notify.sms.enable"));
		systemMap.put("模版消息", environment.getProperty("dts.notify.wx.enable"));
		systemMap.put("快递信息", environment.getProperty("dts.express.enable"));
		systemMap.put("快递鸟ID", environment.getProperty("dts.express.appId"));
		systemMap.put("对象存储", environment.getProperty("dts.storage.active"));
		systemMap.put("本地对象存储路径", environment.getProperty("dts.storage.local.storagePath"));
		systemMap.put("本地对象访问地址", environment.getProperty("dts.storage.local.address"));
		systemMap.put("本地对象访问端口", environment.getProperty("dts.storage.local.port"));

		// 微信相关信息,屏蔽打印控制台
		/*
		 * SystemInfoMap.put(SystemInfoPrinter.CREATE_PART_COPPER + 2, "微信相关");
		 * SystemInfoMap.put("微信APP KEY", environment.getProperty("dts.wx.app-id"));
		 * SystemInfoMap.put("微信APP-SECRET", environment.getProperty("dts.wx.app-secret"));
		 * SystemInfoMap.put("微信支付MCH-ID", environment.getProperty("dts.wx.mch-id"));
		 * SystemInfoMap.put("微信支付MCH-KEY", environment.getProperty("dts.wx.mch-key"));
		 * SystemInfoMap.put("微信支付通知地址", environment.getProperty("dts.wx.notify-url"));
		 */

		// 测试获取System表配置信息
		systemMap.put(SystemInfoPrinter.CREATE_PART_COPPER + 3, "系统设置");
		systemMap.put("自动创建朋友圈分享图", Boolean.toString(SystemConfig.isAutoCreateShareImage()));
		systemMap.put("商场名称", SystemConfig.getMallName());
		systemMap.put("首页显示记录数：NEW,HOT,BRAND,TOPIC,CatlogList,CatlogMore",
				SystemConfig.getNewLimit() + "," + SystemConfig.getHotLimit() + "," + SystemConfig.getBrandLimit() + ","
						+ SystemConfig.getTopicLimit() + "," + SystemConfig.getCatlogListLimit() + ","
						+ SystemConfig.getCatlogMoreLimit());

		return systemMap;
	}
}
